home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/memory.h>
-
- #include <intuition/intuition.h>
- #include <intuition/intuitionbase.h>
- #include <intuition/screens.h>
-
- #include <dos/dos.h>
-
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/alib_protos.h>
-
- #include "FlyingToaster.h"
- #include "images.h"
- #include "/defs.h"
-
- #define IM_WIDTH 64
- #define IM_HEIGHT 64
- #define IM_RADIUS 120
- #define LOOPRATE 10
- #define FACERATE 10
- #define RATE_DEC 5
- #define FT_SPEED ( RangeRand( 4 ) + 1 )
- #define FT_RATE( x ) ( 2 * ( 4 - ft[x].speed ))
- #define MAX_FT 40
-
- struct mPrefObject {
- LONG Objects;
- LONG Speed;
- };
-
- struct object{
- int delay;
- int x,y;
- int old_x,old_y;
- int speed;
- int rate;
- int phase;
- int rate_count;
- struct sequence *seq;
- };
-
- extern struct mPrefObject nP;
- extern ULONG Mode;
- extern UBYTE *prefData;
- struct object *ft;
- USHORT nr_objects;
- struct sequence *seq_list[] = { NULL, &default_seq, &loop_seq, &face_seq };
-
- LONG check_collision( LONG i, LONG x, LONG y )
- {
- LONG j, jx, jy;
-
- x += IM_WIDTH / 2;
- y += IM_HEIGHT / 2;
-
- for( j = 0; j < nr_objects; j++ ) {
- if( j != i && !ft[j].delay ) {
- jx = ft[j].x + IM_WIDTH / 2;
- jy = ft[j].y + IM_HEIGHT / 2;
-
- if((( jx - x )*( jx - x )+( jy - y )*( jy - y )) <= 4 * IM_RADIUS * IM_RADIUS ) return( j );
- }
- }
- return( -1 );
- }
-
- VOID calc_new_pos( LONG i )
- {
- LONG x, y, c;
-
- x = ft[i].x - ft[i].speed;
- y = ft[i].y + 2;
-
- ft[i].old_x = ft[i].x;
- ft[i].old_y = ft[i].y;
-
- if(( c = check_collision( i, x, y )) != -1 ) {
- x = ft[i].x;
- y += 2;
- if(( c = check_collision( i, x, y )) != -1 ) {
- y = ft[i].y - 4;
- if(( c = check_collision( i, x, y )) != -1 ) return;
- }
- }
- ft[i].x = x;
- ft[i].y = y;
- }
-
- BOOL find_launch_pos( LONG i, LONG wid, LONG hei )
- {
- BOOL colides;
- LONG j, x, y, ix, iy, jx, jy;
-
- x = wid;
- y = hei;
-
- FOREVER {
- if( x <= 2*IM_WIDTH && y <= -IM_HEIGHT ) return(FALSE);
-
- ix = x + IM_WIDTH / 2;
- iy = y + IM_HEIGHT / 2;
- colides = FALSE;
-
- for( j = 0; j < nr_objects && !colides; j++ ) {
- if( i != j ) {
- jx = ft[j].x + IM_WIDTH / 2;
- jy = ft[j].y + IM_HEIGHT / 2;
-
- if((( jx - ix )*( jx - ix )+( jy - iy )*( jy - iy )) <=
- (4 * IM_RADIUS * IM_RADIUS)) colides = TRUE;
- }
- }
-
- if( !colides ) {
- ft[i].x = ft[i].old_x = x;
- ft[i].y = ft[i].old_y = y;
- return( TRUE );
- }
- if( y > - IM_HEIGHT ) y -= IM_HEIGHT;
- else x -= IM_WIDTH;
- }
- }
-
- VOID goto_next_img( struct object *obj, struct sequence *next_seq )
- {
- obj->phase++;
- if( obj->phase >= obj->seq->img_count ) {
- obj->phase = 0;
- if( !next_seq ) {
- obj->seq = obj->seq->next_sequence;
- if( !RangeRand( LOOPRATE )) {
- obj->rate = RATE_DEC - 1;
- obj->seq = &loop_seq;
- } else if( !RangeRand( FACERATE )) {
- obj->rate = RATE_DEC - 1;
- obj->seq = &face_seq;
- }
- } else obj->seq = next_seq;
- }
- }
-
- VOID blank( VOID )
- {
- struct mPrefObject *mP;
- struct Screen *FTScr;
- struct Window *win;
- struct RastPort *Rast;
- struct ColorSpec C[] = { 0, 0x00, 0x00, 0x00, 1, 0x0F, 0x0F, 0x0F, ~0, 0x00, 0x00, 0x00 };
- UWORD P[] = { 65535 };
- LONG delay_rate = 2, i;
-
- if( FlyingToasterWnd ) mP = &nP;
- else mP = ( struct mPrefObject * )prefData;
-
- nr_objects = mP->Objects;
- delay_rate = mP->Speed;
-
- if(!( ft = AllocVec( sizeof( struct object ) * nr_objects, MEMF_CLEAR ))) return;
-
- if( FTScr = OpenScreenTags( NULL, SA_DisplayID, Mode, SA_Depth, 1, SA_Overscan, OSCAN_STANDARD, SA_Colors,
- (LONG)C, SA_Type, CUSTOMSCREEN, SA_Pens, (LONG)P, SA_Quiet, TRUE, SA_Behind, TRUE, TAG_DONE )) {
-
- SetRGB4( &( FTScr->ViewPort ), 0, 0, 0, 0 );
- SetRGB4( &( FTScr->ViewPort ), 1, 0x0F, 0x0F, 0x0F );
- setCopperList( FTScr->Height, 1L , &( FTScr->ViewPort ));
-
- if( win = OpenWindowTags( NULL, WA_Width, FTScr->Width, WA_Height, FTScr->Height, WA_IDCMP, 0L,
- WA_Flags, WFLG_SIMPLE_REFRESH|WFLG_BORDERLESS, WA_CustomScreen, FTScr, TAG_DONE )) {
-
- Rast = win->RPort;
- SetRast( Rast, 0 );
- SetAPen( Rast, 0 );
-
- for( i = 0; i < nr_objects; i++ ) {
- if( !find_launch_pos( i, win->Width, win->Height )) ft[i].delay = 30;
- else ft[i].delay = RangeRand( 50 );
-
- ft[i].phase = RangeRand( IMAGEMAX );
- ft[i].seq = &default_seq;
- ft[i].speed = FT_SPEED;
- ft[i].rate = ft[i].rate_count = FT_RATE( i );
- }
-
- BlankMousePointer();
- ScreenToFront( FTScr );
-
- while(!( SetSignal( 0L, 0L ) & SIGBREAKF_CTRL_C )) {
- for( i = 0; i < nr_objects; i++ ) {
- if( !ft[i].delay ) {
- calc_new_pos( i );
- ft[i].rate_count -= RATE_DEC;
-
- if( ft[i].rate_count < 0 ) {
- ft[i].rate_count = ft[i].rate;
- goto_next_img( &ft[i], NULL );
- }
-
- if(( ft[i].old_x != ft[i].x || ft[i].old_y != ft[i].y )) {
- if( ft[i].y > ft[i].old_y ) EraseRect( Rast, ft[i].old_x,
- ft[i].old_y, ft[i].old_x + IM_WIDTH,
- ft[i].y + 1 );
- if( ft[i].x < ft[i].old_x ) EraseRect( Rast,
- ft[i].x + IM_WIDTH - 1, ft[i].y,
- ft[i].old_x + IM_WIDTH, ft[i].old_y + IM_HEIGHT );
- }
-
- DrawImage( Rast, ft[i].seq->img[ft[i].phase], ft[i].x, ft[i].y );
-
- if( ft[i].x < -( IM_WIDTH + 1 ) || ft[i].y > win->Height )
- ft[i].delay = RangeRand( 50 );
- } else {
- ft[i].delay--;
- if( !ft[i].delay ) {
- if( find_launch_pos( i, win->Width, win->Height )) {
- ft[i].speed = FT_SPEED;
- ft[i].rate = ft[i].rate_count = FT_RATE( i );
- } else ft[i].delay = 30;
- }
- }
- }
- Delay( 3 - delay_rate );
- }
- SetSignal( 0L, SIGBREAKF_CTRL_C );
- UnblankMousePointer();
- CloseWindow( win );
- }
- CloseScreen( FTScr );
- }
- FreeVec( ft );
- }
-